package com.avengers.core.model;

/**
 * @author yu.wang
 * @since 6/20/22 5:30 PM
 **/
public class CommonColumn implements DbColumn {
    private final String string;
    private final Boolean isEscape;

    public static final CommonColumn length_name = new CommonColumn("length(name)");
    public static final CommonColumn char_length_name = new CommonColumn("char_length(name)");
    public static final CommonColumn count = new CommonColumn("count(1) as count");
    public static final CommonColumn COUNT_SORT = new CommonColumn("count(1)");
    public static final String COLUMN_NAME_COUNT = "count";

    private CommonColumn(String string, boolean isEscape) {
        this.string = string;
        this.isEscape = isEscape;
    }

    private CommonColumn(String string) {
        this(string, true);
    }

    public static CommonColumn as(String columnStr) {
        return new CommonColumn(columnStr);
    }

    public static CommonColumn as(String columnStr, boolean isEscape) {
        return new CommonColumn(columnStr, isEscape);
    }

    @Override
    public boolean isEscape() {
        return isEscape;
    }

    @Override
    public String toString() {
        return string;
    }

    @Override
    public String name() {
        return string;
    }
}